import React from 'react'
import { Navigate, useLocation } from 'react-router-dom'
import { useAppSelector } from '/@/hooks'

interface IPropType {
  component: React.FC
}

const PrivateRoute: React.FC<IPropType> = ({ component: Component }) => {
  let user = useAppSelector((state) => state.accout)
  let location = useLocation()
  return user.username !== '' ? <Component /> : <Navigate to="/login" state={{ from: location }} />
}

export default PrivateRoute
